
local buyCoinCfg = {
	-- 680,1680,3980,
    1,2,3
}

local image_licenseBt = "warningPanel/goumai-m.png"

---------------
BuyCoinPanel = class("BuyCoinPanel")

function BuyCoinPanel.create(parent)
    local panel = BuyCoinPanel.new()
    panel:init(parent)

    panel.view:setPosition(pp.center.x, pp.center.y)
    uiEffect.bounceIn(panel.view)    
    parent:base_onOpenWin(panel)

    return panel
end


function BuyCoinPanel:init(parent)
    self.view = ccs.GUIReader:getInstance():widgetFromJsonFile("buyCoinPanel.json")
    parent.widget:addChild(self.view)
    self.view:setLocalZOrder(pp.z_pay)
    self.parent = parent

    --close
    local function btCloseCallback(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            AudioEngine.playEffect(sound.btn2)
        elseif eventType == ccui.TouchEventType.ended then
            self:close()
        end
    end
    self.bt_close = self.view:getChildByName("_close")
    self.bt_close:addTouchEventListener(btCloseCallback)
    
   
    --bt1
    do
        local function btCoinCallback(sender, eventType)
            if eventType == ccui.TouchEventType.began then
                AudioEngine.playEffect(sound.btn1)
            elseif eventType == ccui.TouchEventType.ended then
--                uiEffect.bounceOut(self.view, true)
--                self.parent:base_onCloseWin(self)


                if pchCenter:order(pchCfg.item.JinBi_680) == false then
                    uiPopNotify:popString(self.parent.widget, strDef.str_orderFail)
                end
            end
        end
        local bt_coin = self.view:getChildByName("_bt1")
        bt_coin:addTouchEventListener(btCoinCallback)
        --uiEffect.jelly(bt_coin)
        if gameData.SwichByServer.LicenseMode then
            bt_coin:loadTextureNormal(image_licenseBt, ccui.TextureResType.localType)
        end
    end
    
    --bt2
    do
        local function btCoinCallback(sender, eventType)
            if eventType == ccui.TouchEventType.began then
                AudioEngine.playEffect(sound.btn1)

            elseif eventType == ccui.TouchEventType.ended then
--                uiEffect.bounceOut(self.view, true)
--                self.parent:base_onCloseWin(self)

                if pchCenter:order(pchCfg.item.JinBi_1680) == false then
                    uiPopNotify:popString(self.parent.widget, strDef.str_orderFail)
                end
            end
        end
        local bt_coin = self.view:getChildByName("_bt2")
        bt_coin:addTouchEventListener(btCoinCallback)
        --uiEffect.jelly(bt_coin)
        if gameData.SwichByServer.LicenseMode then
            bt_coin:loadTextureNormal(image_licenseBt, ccui.TextureResType.localType)
        end
    end

    --bt3
    do
        local function btCoinCallback(sender, eventType)
            if eventType == ccui.TouchEventType.began then
                AudioEngine.playEffect(sound.btn1)

            elseif eventType == ccui.TouchEventType.ended then
--                uiEffect.bounceOut(self.view, true)
--                self.parent:base_onCloseWin(self)

                if not IS_CHEAP_MODE then
                    if pchCenter:order(pchCfg.item.JinBi_3980) == false then
                        uiPopNotify:popString(self.parent.widget, strDef.str_orderFail)
                    end
                else
                    gameUtil.buyCoin(3980)
                    uiPopNotify:popString(gameUtil.curLuaScene.widget, "获得金币3980枚")
                    -- uiPopNotify:popString(gameUtil.curLuaScene.widget, "支付失败,请稍后再试")
                    gameUtil.curLuaScene:refreshCoin(userData.coin)
                end      
            end
        end
        local bt_coin = self.view:getChildByName("_bt3")
        bt_coin:addTouchEventListener(btCoinCallback)
        --uiEffect.jelly(bt_coin)
        if gameData.SwichByServer.LicenseMode then
            bt_coin:loadTextureNormal(image_licenseBt, ccui.TextureResType.localType)
        end
    end

    --recommend
    local holder_rec = self.view:getChildByName("_recommend")
--    UIInfo.inst:readInfoFromNode(holder_rec)
--    holder_rec:removeFromParent(true)
--    local rec = ccui.ImageView:create("common/srcres/jian.png", ccui.TextureResType.localType)
--    UIInfo.inst:setInfoToNode(rec)
--    rec:setScale(1.2)
--    uiEffect.blink(rec)
--    self.view:addChild(rec)
    holder_rec:removeFromParent(true)
    
end 

function BuyCoinPanel:close()
    -- body
    uiEffect.bounceOut(self.view, true)
    self.parent:base_onCloseWin(self)
end